package demo2;

public class Main {
    public static void PhoneCall(Phone phone){
        phone.callPhone();
    }

    public static void main(String[] args) {
        Phone phone4 = new Phone4("123");
        Phone phone10 = new Phone10("456","张三","通化");

        System.out.println(phone4 instanceof Phone10);

        System.out.println(phone4 instanceof Phone4);


        if(phone10 instanceof Phone10){
            Phone10 phone101 = (Phone10)phone10;
            phone101.weChatPhone();
            phone101.callPhone();
        }

//        if("父类对象" instanceof "子类类名"){true false
//            //检测父类对象向下转型到子类是否安全
//
//        }

        Phone[] phones = new Phone[]{phone4,phone10};

        for (Phone phone: phones){
            PhoneCall(phone);

        }
    }
}

class Phone{
    String num;

    public Phone(String num) {
        this.num = num;
    }

    public void callPhone(){

    }
}

class Phone4 extends Phone{
    public Phone4(String num) {
        super(num);
    }

    @Override
    public void callPhone() {
        System.out.println("电话号码：" + num);
    }
}

class Phone10 extends Phone{

    String name;
    String address;

    public Phone10(String num, String name, String address) {
        super(num);
        this.name = name;
        this.address = address;
    }

    public void weChatPhone(){
        System.out.println("视频通话");
    }

    @Override
    public void callPhone() {
        System.out.println("号码：" + this.num);
        System.out.println("地区：" + this.address);
        System.out.println("姓名：" + this.name);
    }
}
